package com.wlb365.financing.modules.trade.controller;

import com.wlb365.financing.common.constants.SysConstant;
import com.wlb365.financing.modules.esign.service.ESignService;
import com.wlb365.financing.modules.sys.entity.Dict;
import com.wlb365.financing.modules.sys.service.IDeptService;
import com.wlb365.financing.modules.sys.service.IDictService;
import com.wlb365.financing.modules.sys.service.IUserService;
import com.wlb365.financing.modules.trade.service.IAuditService;
import com.wlb365.financing.modules.trade.service.IDataService;
import com.wlb365.financing.modules.trade.service.IVoucherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 凭证下载管理类.
 *
 * @author zwh
 * @version 1.0
 */
@RestController
@RequestMapping("voucher/download")
public class VoucherDownloadController {
    @Autowired
    private IVoucherService voucherService;
    @Autowired
    private IDataService dataService;
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IDictService dictService;
    @Autowired
    private IAuditService auditService;
    @Autowired
    private IUserService userService;
    @Autowired
    private ESignService eSignService;

    /**
     * 凭证下载列表页面.
     * @param
     * @author zwh
     * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequiresPermissions("voucher:download:index")
    @GetMapping(value = "index")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("voucher/voucher_download.html");
        mv.addObject("supplierList", deptService.listDeptByType(SysConstant.DEPT_TYPE_0));
        mv.addObject("coreList", deptService.listDeptByType(SysConstant.DEPT_TYPE_1));
        mv.addObject("bankList", deptService.listDeptByType(SysConstant.DEPT_TYPE_2));
        List<Dict> dicts = dictService.listAllDictItemByCode("VOUCHER");
        //只过滤出 03,31,33,34
        mv.addObject("dictList", dicts.stream().filter(s-> (s.getCode().equals("03") || s.getCode().equals("31") || s.getCode().equals("33") || s.getCode().equals("34"))).collect(Collectors.toList()));
        return mv;
    }



}
